/*
 * @Author: 薛严 348352046@qq.com
 * @Date: 2023-05-05 11:20:53
 * @LastEditors: 薛严 348352046@qq.com
 * @LastEditTime: 2023-05-05 15:27:03
 * @FilePath: /gd-auth-demo-h5/src/components/crypto.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import CryptoJS from 'crypto-js'

export function createAes(encryptKey) {
  const key = CryptoJS.enc.Utf8.parse(encryptKey)
  return {
    decrypt(word) {
      return CryptoJS.AES.decrypt(word, key, {
        mode: CryptoJS.mode.ECB
      }).toString(CryptoJS.enc.Utf8)
    },
    encrypt(word) {
      const wordc = CryptoJS.enc.Utf8.parse(word)
      return CryptoJS.AES.encrypt(wordc, key, {
        mode: CryptoJS.mode.ECB
      }).toString()
    }
  }
}
